package com.eastcom.providor.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.eastcom.bm.atom.CalendarPolicy;
import com.eastcom.client.MapEntryNode;
import com.eastcom.providor.dao.ICalendarPolicyDao;
import com.eastcom.providor.service.BaseService;
import com.eastcom.providor.service.ICalendarPolicyService;
import com.eastcom.providor.service.extview.CalendarPolicyUtil;

public class CalendarPolicyService extends BaseService implements ICalendarPolicyService {

	private ICalendarPolicyDao calendarPolicyDao;
	
	public void setCalendarPolicyDao(ICalendarPolicyDao calendarPolicyDao) {
		this.calendarPolicyDao = calendarPolicyDao;
	}

	public List<CalendarPolicy> getAllCalendarPolicy() {
		try{
			//ICalendarPolicyDao policyDao=DAOFactory.getInstance().getCalendarPolicyDao();
			return calendarPolicyDao.getAllCalendarPolicy();
		}
		catch(Exception e){
			log.error("ICalendarPolicyService getAllCalendarPolicy error",e);
		}
		/*
		finally{
			JDBCTemplate.doSessionFinally();
		}*/
		
		return null;
	}

	public CalendarPolicy getCalendarPolicyByUUID(String policyUUID) {
        try{
        	//ICalendarPolicyDao policyDao=DAOFactory.getInstance().getCalendarPolicyDao();
			return calendarPolicyDao.getCalendarPolicyByUUID(policyUUID);
		}
		catch(Exception e){
			log.error("ICalendarPolicyService getCalendarPolicyByUUID error",e);
		}
		/*
        finally{
        	JDBCTemplate.doSessionFinally();
		}
		*/
        
		return null;
	}
	
	public List<MapEntryNode> getAllCalendarPolicyMapEntry(){
		List<MapEntryNode> retVal=new ArrayList<MapEntryNode>();
		try{
			for(CalendarPolicy cal:getAllCalendarPolicy()){
				retVal.add(CalendarPolicyUtil.createMapEntryByCalendarPolicy(cal));
			}
		}catch (Exception e) {
			e.printStackTrace();
			log.error("calendarPolicyDao.getAllCalendarPolicy is error",e);
		}
		return retVal;
	}

}
